home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Developer Kits / BBEdit Extension Dev. Kit / Examples / BB ROT13.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-09  |  891 b   |  47 lines  |  [TEXT/KAHL]

  1. #include <Types.h>
  2. #include <Windows.h>
  3. #include <Dialogs.h>
  4. #include <Sound.h>
  5. #include <StandardFile.h>
  6.  
  7. #include "ExternalInterface.h"
  8.  
  9. pascal void main (ExternalCallbackBlock *cbb, WindowPeek w)
  10. {
  11.     if (cbb->version < 2)
  12.         SysBeep(10);
  13.     else if (!w && w->windowKind != userKind)
  14.         SysBeep(10);
  15.     else
  16.     {
  17.         long selStart, selEnd, firstChar;
  18.  
  19.         cbb->GetSelection (&selStart,&selEnd,&firstChar);
  20.  
  21.         if (selStart == selEnd)
  22.             SysBeep(10);
  23.         else
  24.         {
  25.             Handle text = cbb->GetWindowContents ((WindowPtr) w);
  26.             char *scan = *text + selStart, *top = *text + selEnd;
  27.  
  28.             while (scan < top)
  29.             {
  30.                 if (    (*scan >= 'A' && *scan <= 'M')        ||
  31.                         (*scan >= 'a' && *scan <= 'm')        )
  32.                 {
  33.                     *scan += 13;
  34.                 }
  35.                 else if (    (*scan >= 'n' && *scan <= 'z')    ||
  36.                             (*scan >= 'N' && *scan <= 'Z')    )
  37.                 {
  38.                     *scan -= 13;
  39.                 }
  40.                 ++scan;
  41.             }
  42.  
  43.             cbb->ContentsChanged ((WindowPtr) w);
  44.         }
  45.     }
  46. }
  47.